package com.edgclub.edg.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.edgclub.edg.R;
import com.edgclub.edg.activity.UserInfoOtherActivity;
import com.edgclub.edg.adapter.adapteruitls.GzBaseAdapter;
import com.edgclub.edg.adapter.adapteruitls.MyItemClickListener;
import com.edgclub.edg.adapter.adapteruitls.MyItemLongClickListener;
import com.edgclub.edg.adapter.adapteruitls.RViewHolder;
import com.edgclub.edg.model.User;
import com.edgclub.edg.utils.GlideUtil.GlideUtils;

import java.util.ArrayList;

/**
 */
public class BBDetailLikeUserAdapter extends GzBaseAdapter {
    private Context mContext;

    private ArrayList<User> likeUsers;

    private GlideUtils glideUtils;

    private onClickImageClickListener clickImageClickListener;

    public BBDetailLikeUserAdapter(Context mContext) {
        this.mContext = mContext;
        glideUtils = new GlideUtils();
    }

    public onClickImageClickListener getClickImageClickListener() {
        return clickImageClickListener;
    }

    public void setClickImageClickListener(
            onClickImageClickListener clickImageClickListener) {
        this.clickImageClickListener = clickImageClickListener;
    }

    public ArrayList<User> getLikeUsers() {
        return likeUsers;
    }

    public void setLikeUsers(ArrayList<User> likeUsers) {
        this.likeUsers = likeUsers;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_user_logo_image,viewGroup,false);
        ViewHolder vh = new ViewHolder(view,mListener,mLongClickListener);
        return vh;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        final User likeUser1 = likeUsers.get(position);
        User likeUser = likeUsers.get(position);
        glideUtils.Glidde_loadCropCircleImage(mContext,likeUser.getLogo(), viewHolder.image);
        viewHolder.image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext, UserInfoOtherActivity.class);
                intent.putExtra("user",likeUser1);
                mContext.startActivity(intent);
            }
        });
        if(null!=likeUser.getUserAuth()){
            if ("-1".equals(likeUser.getUserAuth().getType())){
                viewHolder.vip.setVisibility(View.GONE);
            }
            if("0".equals(likeUser.getUserAuth().getType())){
                viewHolder.vip.setVisibility(View.VISIBLE);
                viewHolder.vip.setImageResource(R.drawable.v_huan);
            }else if("1".equals(likeUser.getUserAuth().getType())){
                viewHolder.vip.setVisibility(View.VISIBLE);
                viewHolder.vip.setImageResource(R.drawable.v_lan);
            }
        }else{
            viewHolder.vip.setVisibility(View.GONE);
        }

    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public int getItemCount() {
        if (null == likeUsers) {
            return 0;
        }
        return Math.min(8, likeUsers.size());
    }



    //自定义的ViewHolder，持有每个Item的的所有界面元素
    public static class ViewHolder extends RViewHolder {
        public ImageView image,vip;

        public ViewHolder(View view, MyItemClickListener mListener, MyItemLongClickListener mLongClickListener){
            super(view,mListener,mLongClickListener);
            image = (ImageView) view.findViewById(R.id.image);
            vip = (ImageView) view.findViewById(R.id.vip);

        }
    }

    /**
     *
     */
    public interface onClickImageClickListener {
        public void onClick(int position, int mTopicPosition);

    }
}
